<template>
    <div>
        <el-input v-model="input" placeholder="请输入国家"></el-input>
        <br><br>
        <el-button id="btn_search" type="primary" @click="searchByCountryName()">搜索</el-button>
        <br><br>
        <el-input v-model="input2" placeholder="请输入地区"></el-input>
        <br><br>
        <el-button id="btn_search2" type="primary" @click="searchByStateName()">搜索</el-button>
        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="id"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="state"
                    label="地区"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="country"
                    label="国家">
            </el-table-column>
            <el-table-column
                    prop="latestTotalCases"
                    label="病例总数">
            </el-table-column>
            <el-table-column
                    prop="diffFromPrevDay"
                    label="新增病例">
            </el-table-column>
            <el-table-column
                    label="操作">
                <template slot-scope="scope">
                    <el-button type="primary" @click="insurance(scope.row.id)">查看详情</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

</template>

<script>
export default {
    name: "Table",
    methods:{
        searchByCountryName(){
            let _this = this;
            axios.get('http://localhost:8081/data/byCountryName/'+this.input).then(function (response) {
                console.log(response.data);
                _this.tableData = response.data;
            })
        },
        searchByStateName(){
            let _this = this;
            axios.get('http://localhost:8081/data/byStateName/'+this.input2).then(function (response) {
                console.log(response.data);
                _this.tableData = response.data;
            })
        },
        insurance(id) {
            //直接调用$router.push 实现携带参数的跳转
            this.$router.push({
                path: `/statechart/${id}`,
            })
        }
    },
    created() {
        let _this = this;
        axios.get('http://localhost:8081/data/all').then(function (response) {
            console.log(response.data);
            _this.tableData = response.data;
        })
    },
    data() {
        return {
            input: '',
            input2:'',
            tableData: []
        }
    }
}
</script>

<style scoped>

</style>
